﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ProduceBasicData.Api.Application.Command.Process;
using ProduceBasicData.Api.DTO;
using ProduceBasicData.ErrorCode;

namespace ProduceBasicData.Api.Controllers
{
    /// <summary>
    /// 工序维护控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProcessController : ControllerBase
    {
        private readonly IMediator mediator;

        public ProcessController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 工序维护信息录入接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> CreateProcess(CreateProcessCommand request)
        {
            return await mediator.Send(request);    
        }

        /// <summary>
        /// 工序维护信息展示接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiPaging<ProcessDto>> GetProcess([FromQuery]GetProcessCommand request)
        {
            return  mediator.Send(request);
        }

        /// <summary>
        /// 工序维护信息更新接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> UpdateProcess(UpdateProcessCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 工序维护信息删除接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> DeleteProcess(DeleteProcessCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 工序维护信息批量删除接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> DeleteRangeProcess(DeleteProcessRangeCommand request)
        {
            return await mediator.Send(request);
        }
    }
}
